package edu.xust.utils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class ReflectUtils {
    /**
     * 获取给 "方法参数" 进行注解的值
     *
     * @param method 要获取参数名的方法
     * @return 按参数顺序排列的参数名列表
     */
    public static Class[] getMethodParameterNamesByAnnotation(Method method,Class annotationCls) {
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        if (parameterAnnotations == null || parameterAnnotations.length == 0) {
            return null;
        }
        Class[] parameterNames = new Class[parameterAnnotations.length];
        int i = 0;
        System.out.println("---------------------");
        for (Annotation[] parameterAnnotation : parameterAnnotations) {
            for (Annotation annotation : parameterAnnotation) {
                System.out.println(annotation.annotationType().getName() + " "+ annotationCls.getName());
                   if(annotation.annotationType().getName().equals( annotationCls.getName())) {
                String name = annotation.annotationType().getSimpleName();
                        parameterNames[i++] = annotation.annotationType();
                   }

            }
        }
        return parameterNames;
    }
}
